package com.xiaoke.mapreduce.wc;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

public class MyWordCount {

    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration(true);

        //让框架知道是windows异构平台运行
        configuration.set("mapreduce.app-submission.cross-platform","true");

        configuration.set("mapreduce.framework.name", "local");

        // 点击job下面的参数根据example写
        Job job = Job.getInstance(configuration);
        //job.setJar("D:\\code\\mayun_hadoop\\test\\hadoop\\target\\hadoop-hdfs-1.0-SNAPSHOT.jar");


        job.setJarByClass(MyWordCount.class);

        // Specify various job-specific parameters
        job.setJobName("xiaokeke3");

        Path inputPath = new Path("/data/wc/input");
        TextInputFormat.setInputPaths(job, inputPath);

        Path outputPath = new Path("/data/wc/output4");
        if (outputPath.getFileSystem(configuration).exists(outputPath))
            outputPath.getFileSystem(configuration).delete(outputPath, true);
        TextOutputFormat.setOutputPath(job, outputPath);

        job.setMapperClass(MyMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setReducerClass(MyReducer.class);

        job.waitForCompletion(true);

    }
}
